package com.yj.rest;

import com.yj.po.User;
import com.yj.result.ReturnResp;
import com.yj.service.UserService;
import com.yj.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.PostConstruct;

@Slf4j
//@RequestMapping("")
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/system/user")
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView("system/user/user");
        return mv;
    }

    @GetMapping("/system/user/add")
    public String addUser(@RequestBody User user){
        userService.addUser(user);
        return "system/user/user-add";
    }

    @GetMapping("/system/user/edit")
    public String editUser(){
        return "system/user/user-edit";
    }

    @PostMapping("/login")
    @ResponseBody
    public ReturnResp<?> login(User user){
        User login = userService.login(user);
        return ReturnResp.success(login);
    }

    @PostMapping("/saveUser")
    @ResponseBody
    public ReturnResp<?> saveUser(@RequestBody User user){
        userService.addUser(user);
        return ReturnResp.success();
    }

}
